import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class CameraPage extends StatefulWidget {
  const CameraPage({super.key});

  @override
  State<CameraPage> createState() => _CalculatorPageState();
}

class _CalculatorPageState extends State<CameraPage> {

  final _platform = const MethodChannel('samples.flutter.dev/way1_add');

  //调用加法方式1-MethodChannel
  Future<String> getCamera() async {

    String result = (await _platform.invokeMethod<int>('getCamera')) as String;
    print('异步操作完成，计算结果为：$result');
    setState(() {

    });
    return '异步操作完成';
  }


  @override
  void dispose() {
    super.dispose();
  }



  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('原生能力调用页面'),
      ),
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(20.0),
          child: Column(
            children: [
              ElevatedButton(
                onPressed: (){

                }, child: const Text(
                '点击打开相机',
                style: TextStyle(fontSize: 16),
              ),
              )
            ],
          ),
        ),
      ),
    );
  }
}

// 自定义按钮组件
class CustomCalculatorButton extends StatelessWidget {
  final String text;
  final VoidCallback onPressed;

  const CustomCalculatorButton({
    super.key,
    required this.text,
    required this.onPressed,
  });

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        const SizedBox(height: 20),
        ElevatedButton(
          onPressed: onPressed,
          style: ElevatedButton.styleFrom(
            padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 30),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(10.0),
            ),
          ),
          child: Text(
            text,
            style: const TextStyle(fontSize: 16),
          ),
        )
      ],
    );
  }
}
